﻿using System;
using System.Collections.Generic;
using System.Text;
using WITS.Framework.Interface;

namespace WITS.Framework.Data.Base
{
    public abstract class ReturnStd : IStandardData, IReturn
    {
        protected Dictionary<string, ReElement> _p = new Dictionary<string, ReElement>();

        protected void AddReElement(string name, Type t)
        {
            if (!this._p.ContainsKey(name))
            {
                this._p.Add(name, new ReElement(name, t));
            }
        }
        protected void AddReElement(string name)
        {
            if (!this._p.ContainsKey(name))
            {
                this._p.Add(name, new ReElement(name));
            }
        }

        #region IStandardData Members

        public string ToStdFormatString()
        {
            return "";
        }

        public string ToString(string format)
        {
            return "";
        }

        public StdType StdType
        {
            get { return StdType.Return; }
        }

        #endregion

        #region IParameters Members

        public abstract string[] GetReturnList();
       
        public T GetValue<T>(string p)
        {
            if (_p.ContainsKey(p))
            {
                if (typeof(T) == _p[p].PType)
                {
                    if (_p[p].Value != null)
                        return (T)_p[p].Value;
                    else
                        return default(T);
                }
                else
                {
                    return default(T);
                }
            }
            else
            {
                return default(T);
            }
        }

        #endregion
    }
}
